﻿using System.Collections;
using UnityEngine;

public class CheckpointManager : MonoBehaviour
{
    public Checkpoint[] checkpoints;
    public int ActiveCheckpointIndex
    {
        get
        {
            for (int i = 0; i < checkpoints.Length; ++i)
            {
                if (checkpoints[i].Active)
                    return i;
            }
            return -1;
        }
    }
    public int GetCheckPointIndex(Checkpoint c)
    {
        for (int i = 0; i < checkpoints.Length; ++i)
        {
            if (c == checkpoints[i])
                return i;
        }
        return -1;
    }

    private void Awake()
    {
        checkpoints = GetComponentsInChildren<Checkpoint>();
        int startindex =  Service.Get<GameManager>().StartCheckPointIndex;
        checkpoints[startindex].Spawn();
    }
}
